clear;
%Assignment
disp('------------------------Assignment A--------------------------');
M=[0.0 2.9;0.5 2.7;1.0 4.8;1.5 5.3;2.0 7.1;2.5 7.6;3.0 7.7;
   3.5 7.6;4.0 9.4;4.5 9.0;5.0 9.6;5.5 10.0;6.0 10.2;6.5 9.7;
   7.0 8.3;7.5 8.4;8.0 9.0;8.5 8.3;9.0 6.6;9.5 6.7;10.0 4.1;];
Order =2;
%Step1 Build Gram matrix and RHS
[Gram,RHS]=DLS_GramBuilder(M,Order);
%Step2 Solve linear equations
coef_A = Gram\RHS;
%Step3 Output
disp(coef_A);
disp('------------------------Assignment B--------------------------');
%Step1 Build overdetermined matrix and RHS
[Matrix_B,RHS_B]=DLS_GSBuilder(M,Order);
%Step2 QR factor
[Q_Matrix_1,R_Matrix_1]=QR_factor(Matrix_B);
%Step3 Solve linear equations
c=(Q_Matrix_1)'*RHS_B;
coef_B=R_Matrix_1\c;
%Step4 Output
disp(coef_B);
fprintf('Cond(Gram)=%f,Cond(R_1)=%f.\n',cond(Gram),cond(R_Matrix_1));